package 进阶.线程.线程安全.demo01同步方法;

public class RunnaleImpl implements Runnable {


    //创建锁对象
    Object obj = new Object();


    private int t = 1000;
    @Override
    public void run() {

        while (true){
            //同步代码块
            synchronized (obj){
                if(t > 0){
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("卖出了第"+ t + "张票");
                    t --;
                    System.out.println(Thread.currentThread().getName());
                }
            }
        }
    }
}
